

import {followApi, unfollow as unfollowApi} from '@/api/article.js'
import { computed } from 'vue'
import router from '@/router' 

import checkLogin from '@/utils/checkLogin'

export default function(articleInfo,getArticle ){
	
	let followed_id = computed(function(){
		return articleInfo.value.author_id
	})
	 function follow(){
		 
		 if(!checkLogin()) return 

		 followApi({
			 followed_id:followed_id.value  
		 }).then(res=>{
			 console.log(res)
			 if(res.code == 0){
				 getArticle()
			 }
		 }).catch(err=>{
			 console.log(err)
		 })
	 }
	 function unfollow(){
		  if(!checkLogin()) return 
		 unfollowApi({
		 			 followed_id:followed_id.value  
		 }).then(res=>{
		 			 console.log(res)
		 			 if(res.code == 0){
		 				 getArticle()
		 			 }
		 }).catch(err=>{
		 			 console.log(err)
		 })
		 
		 
	 }
	
	return {
		follow,
		unfollow
		
	}
}


